package 力扣刷题.探索初级算法.数组.两数之和;

import java.util.Arrays;
import java.util.Scanner;

public class Solution {
    public int[] twoSum(int[] nums, int target) {
        int[] resultPositions=new int[2];
        for (int i = 0; i < nums.length; i++) {
            int matchPosition=findSubtractionPos(nums, i+1,target-nums[i]);
            if(matchPosition!=-1) {
                resultPositions[0]=i;
                resultPositions[1]=matchPosition;
                return resultPositions;
            }

        }
        return null;
    }
    public int findSubtractionPos(int[] nums,int startPosition,int subtraction) {
        for (int i = startPosition; i < nums.length; i++) {
            if(nums[i]==subtraction) {
                return i;
            }
        }
        return -1;
    }
    public static void main(String[] args) {
        int len;
        Scanner s=new Scanner(System.in);
        len=s.nextInt();
        int[] nums=new int[len];
        for (int i = 0; i < len; i++) {
            nums[i]=s.nextInt();
        }
        int target=s.nextInt();
        System.out.println(Arrays.toString(new Solution().twoSum(nums, target)));
        for (int i = 0; i < len; i++) {
            System.out.println(nums[i]);
        }
    }
}
